package com.ruoyi.rebateRule.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rebateRule.domain.RebateRule;
import com.ruoyi.rebateRule.service.IRebateRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 返佣规则Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/ruoyi/rebateRule")
public class RebateRuleController extends BaseController
{
    @Autowired
    private IRebateRuleService rebateRuleService;

    /**
     * 查询返佣规则列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:rebateRule:list')")
    @GetMapping("/list")
    public TableDataInfo list(RebateRule rebateRule)
    {
        startPage();
        List<RebateRule> list = rebateRuleService.selectRebateRuleList(rebateRule);
        return getDataTable(list);
    }

    /**
     * 导出返佣规则列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:rebateRule:export')")
    @Log(title = "返佣规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RebateRule rebateRule)
    {
        List<RebateRule> list = rebateRuleService.selectRebateRuleList(rebateRule);
        ExcelUtil<RebateRule> util = new ExcelUtil<RebateRule>(RebateRule.class);
        util.exportExcel(response, list, "返佣规则数据");
    }

    /**
     * 获取返佣规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:rebateRule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(rebateRuleService.selectRebateRuleByRuleId(ruleId));
    }

    /**
     * 新增返佣规则
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:rebateRule:add')")
    @Log(title = "返佣规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RebateRule rebateRule)
    {
        return toAjax(rebateRuleService.insertRebateRule(rebateRule));
    }

    /**
     * 修改返佣规则
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:rebateRule:edit')")
    @Log(title = "返佣规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RebateRule rebateRule)
    {
        return toAjax(rebateRuleService.updateRebateRule(rebateRule));
    }

    /**
     * 删除返佣规则
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:rebateRule:remove')")
    @Log(title = "返佣规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(rebateRuleService.deleteRebateRuleByRuleIds(ruleIds));
    }
}
